<?php if (!defined('THINK_PATH')) exit(); /*a:2:{s:60:"C:\xampp\htdocs\gyrjy/application/admin\view\link\index.html";i:1534256479;s:59:"C:\xampp\htdocs\gyrjy/application/admin\view\link\link.html";i:1534256479;}*/ ?>
<?php $namespace = ns(); ?>
<div class="box" id="<?php echo $namespace; ?>_box"></div>
<script>
    Namespace.register("EBCMS.<?php echo $namespace; ?>");
    $(function(){
        EBCMS.<?php echo $namespace; ?>.queryParams = {
            page:1,
            rows:20,
            order:{
                'sort':'desc',
            },
            model:'admin/link',
        };
        EBCMS.<?php echo $namespace; ?>.refresh = function refresh(p){
            if (p) {
                $.each(p, function(index, val) {
                    if (typeof val == 'object') {
                        EBCMS.<?php echo $namespace; ?>.queryParams[index] = $.extend(EBCMS.<?php echo $namespace; ?>.queryParams[index], p[index]);
                        delete p[index];
                    };
                });
                $.extend(EBCMS.<?php echo $namespace; ?>.queryParams, p);
            };
            EBCMS.CORE.api({
                queryParams:EBCMS.<?php echo $namespace; ?>.queryParams,
                group:'group',
                tpl:'<?php echo $namespace; ?>-table',
                target:'#<?php echo $namespace; ?>_table',
                compileAfter:function(p){
                    $('#<?php echo $namespace; ?>_table').find('.input_sort').focus(function(){
                        EBCMS.<?php echo $namespace; ?>.sortvalue = $(this).val();
                    }).blur(function(){
                        var $this = $(this);
                        if ($this.val() != EBCMS.<?php echo $namespace; ?>.sortvalue) {
                            EBCMS.ACT.togglefield('<?php echo url('admin/link/resort'); ?>',$this.data('id'),$this.val(),'<?php echo $namespace; ?>','resort');
                        };
                    });
                    EBCMS.FN.renderPage({
                        namespace:'<?php echo $namespace; ?>',
                        total:p.data.total,
                    });
                    EBCMS.FN.renderFilter({
                        namespace:'<?php echo $namespace; ?>',
                        filter:{
                            search:{
                                field:'group|title|description|info|url',
                                value:''
                            },
                            status:{
                                field:'status',
                                filters:{'待审核':99,"已通过":1,'已屏蔽':0}
                            },
                            order:{
                                filters:{id:'id',update_time:'更新时间',sort:'权重'}
                            },
                            rows:true,
                        }
                    });
                },
            });
        };
        EBCMS.<?php echo $namespace; ?>.edit = function edit(id){
            EBCMS.CORE.get({
                url:'<?php echo url('admin/link/edit'); ?>',
                queryParams:{
                    id:id,
                },
                target:'#lgModal .modal-content',
            });
        };
        EBCMS.<?php echo $namespace; ?>.add = function add(pid){
            EBCMS.CORE.get({
                url:'<?php echo url('admin/link/add'); ?>',
                queryParams:{
                    pid:pid,
                },
                target:'#lgModal .modal-content',
            });
        };
        EBCMS.CORE.compile({
            tpl:'<?php echo $namespace; ?>-box',
            target:'#<?php echo $namespace; ?>_box',
            compileAfter:function(){
                EBCMS.<?php echo $namespace; ?>.refresh();
            }
        });
    });
</script>

<script id="<?php echo $namespace; ?>-box" type="text/html">
    <div class="header">
        <div class="header-title" onclick="EBCMS.<?php echo $namespace; ?>.refresh();">友情链接管理</div>
        <div id="<?php echo $namespace; ?>_filter" class="footer-page"></div>
        <div class="btn-group">
            <button class="btn btn-primary" onclick="EBCMS.CORE.getconfig('<?php echo eb_encrypt('name|link'); ?>');">设置</button>
            <button class="btn btn-primary" onclick="EBCMS.<?php echo $namespace; ?>.add();">添加</button>
        </div>
    </div>
    <div class="body">
        <div id="<?php echo $namespace; ?>_table" class="box"></div>
    </div>
    <div class="footer">
        <div id="<?php echo $namespace; ?>_page" class="footer-page"></div>
    </div>
</script>

<script id="<?php echo $namespace; ?>-table" type="text/html">
    <table class="table table-bordered table-hover table-ebcms">
        <tbody>
            <tr>
                <!-- <th style="width:70px;">id</th> -->
                <th style="width:210px;">操作</th>
                <th>名称</th>
                <th>连接</th>
                <th>排序</th>
            </tr>
            [[each groups as data group]]
            <tr>
                <th colspan="4">[[group]]</th>
            </tr>
                [[include '<?php echo $namespace; ?>-table-item' data]]
            [[/each]]
        </tbody>
    </table>
</script>

<script id="<?php echo $namespace; ?>-table-item" type="text/html">
    [[each rows as v n]]
        <tr>
            <!-- <td>[[v.id]]</td> -->
            <td>
                <div class="btn-group btn-group-sm">
                [[if v.status==99]]
                <button class="btn btn-danger" onclick="EBCMS.ACT.status('<?php echo url('admin/link/status'); ?>','[[v.id]]','1','<?php echo $namespace; ?>');">通过</button>
                <button class="btn btn-danger" onclick="EBCMS.ACT.status('<?php echo url('admin/link/status'); ?>','[[v.id]]','0','<?php echo $namespace; ?>');">屏蔽</button>
                [[else if v.status==1]]
                <button class="btn btn-primary" onclick="EBCMS.ACT.status('<?php echo url('admin/link/status'); ?>','[[v.id]]','0','<?php echo $namespace; ?>');">已通过</button>
                [[else]]
                <button class="btn btn-warning" onclick="EBCMS.ACT.status('<?php echo url('admin/link/status'); ?>','[[v.id]]','1','<?php echo $namespace; ?>');">未通过</button>
                [[/if]]
                <button class="btn btn-primary" onclick="EBCMS.<?php echo $namespace; ?>.edit('[[v.id]]');">编辑</button>
                <button class="btn btn-primary" onclick="EBCMS.ACT.del('<?php echo url('admin/link/delete'); ?>','[[v.id]]','<?php echo $namespace; ?>');">删除</button>
                </div>
            </td>
            <td>[[v.title]]</td>
            <td>[[v.url]]</td>
            <td><input value="[[v.sort]]" class="form-control input-sm input_sort" data-id="[[v.id]]"></td>
        </tr>
        [[if v.rows]]
            [[include '<?php echo $namespace; ?>-table-item' v]]
        [[/if]]
    [[/each]]
</script>